define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'printmanager/goods/index' + location.search,
                    add_url: 'printmanager/goods/add',
                    edit_url: 'printmanager/goods/edit',
                    del_url: 'printmanager/goods/del',
                    multi_url: 'printmanager/goods/multi',
                    table: 'self_goods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'sort',
                columns: [
                    [{
                            checkbox: true
                        },
                        {
                            field: 'id',
                            title: __('Id')
                        },
                        {
                            field: 'name',
                            title: __('Name'),
                            operate: "LIKE",
                        },
                        {
                            field: 'category_id',
                            title: __('Category_id'),
                            searchable: false,
                            formatter: function(v,r,i){
                                return r.category.name
                            }
                        },
                        {
                            field: 'images',
                            title: __('图集'),
                            searchable: false,
                            formatter: Table.api.formatter.images
                        },
                        {
                            field: 'price',
                            title: __('Price'),
                            operate: 'BETWEEN'
                        },
                        {
                            field: 'shipping_price',
                            title: __('运费'),
                            operate: 'BETWEEN'
                        },
                        {
                            field: 'unit',
                            title: __('单位'),
                            searchable: false,
                        },
                        {
                            field: 'store',
                            title: __('库存'),
                            searchable: false,
                        },
                        {
                            field: 'sort',
                            title: __('排序'),
                            searchable: false,
                            operate: 'RANGE',
                            formatter: Table.api.formatter.edit
                        },
                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'display',
                            title: __('Display'),
                            searchList: {
                                "0": __('Display 0'),
                                "1": __('Display 1')
                            },
                            formatter: Table.api.formatter.toggle
                        },
                        {
                            field: 'sale_num_show',
                            title: __('Sale_num_show'),
                            searchable: false,
                        },
                        {
                            field: 'sale_num',
                            title: __('Sale_num'),
                            searchable: false,
                        },
                        {
                            field: 'gold_num',
                            title: __('Gold_num'),
                            searchable: false,
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});